package com.zrrd.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.stream.Stream;

/**
 * @author WanJl
 * @version 1.0
 * @title StreamDemo
 * @description 获取流
 * @create 2024/6/1
 */
public class StreamDemo02 {
    public static void main(String[] args) {
        //Collection体系的集合可以使用默认的方法stream()生成流
        ArrayList<String> list = new ArrayList<String>();
        Stream<String> listStream = list.stream();

        HashSet<String> hashSet = new HashSet<>();
        Stream<String> hashSetStream = hashSet.stream();

        //Map体系，就需要转换成Set，间接的生成流
        HashMap<Integer, String> hashMap = new HashMap<>();
        Stream<Integer> hashMapStream = hashMap.keySet().stream();
        //数组
        String[] strings={"张三","李四"};
        Stream<String> arrayStream = Arrays.stream(strings);

        //相同类型的多个数据可以通过Stream接口的of方法生成流
        String s1="张三";
        String s2="张三1";
        String s3="张三2";
        String s4="张三3";
        String s5="张三5";
        Stream<String> stringStream = Stream.of(s1, s2, s3, s4, s5);

        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4, 5);

    }
}
